<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Cart extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/products
	 *	- or -  
	 * 		http://example.com/index.php/products/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/products/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{
		//modell
		$this->load->model('Products_model');
		//$this->load->model('Categories_model');
		$data['products_model'] = $this->Products_model;
		//$data['categories_model'] = $this->Categories_model;
		$data['selected_category_id'] = -1;
		
		//view
		$this->load->view('head');
		$this->load->view('header', array('activeLink' => "cart"));
		$this->load->view('cart', $data);
		$this->load->view('footer');
	}
	
	public function add() 
	{
		$productID = $this->input->post('id');
		$quantity = $this->input->post('qty');
		
		$this->load->model('Products_model');
		
		$product = $this->Products_model->getProductById($productID);
		
		$data = array(
		   'id'      => $productID,
		   'qty'     => $quantity,
		   'price'   => intval($product->price),
		   'name'  => $product->name
		);
		
		$this->cart->insert($data);
		
		$this->load->view('head');
		$this->load->view('header', array('activeLink' => "cart"));
		$this->load->view('cart', $data);
		$this->load->view('footer');
	}
	
	public function remove($rowID) {
		$data = array(
		   'rowid' => $rowID,
		   'qty'   => 0
		);

		$this->cart->update($data);
		
		$this->load->view('head');
		$this->load->view('header', array('activeLink' => "cart"));
		$this->load->view('cart', $data);
		$this->load->view('footer');
	}
	
	public function removeall() {
		$this->cart->destroy();
		
		//modell
		$this->load->model('Products_model');
		$data['products_model'] = $this->Products_model;
		//$data['categories_model'] = $this->Categories_model;
		$data['selected_category_id'] = -1;
		
		$this->load->view('head');
		$this->load->view('header', array('activeLink' => "cart"));
		$this->load->view('cart', $data);
		$this->load->view('footer');
	}
}

/* End of file products.php */
/* Location: ./application/controllers/products.php */